<template>
    <div>
        {{this.$route.params.id}}
        <Button>新建表</Button>
        <Button>设计表</Button>
        <Button>打开表</Button>
        <Button>删除表</Button>
        <Button icon="ios-refresh-circle-outline">刷新</Button>
        <Table highlight-row size="small" border :columns="table_head" :data="table_data"></Table>
    </div>
</template>

<script>
    import {getMysqlPool} from '../../../assets/mysqlPool'

    export default {
        name: "table-list",
        data () {
            return {
                mysqlPool: null,

                table_head: [],
                table_data: []
            }
        },
        methods: {
            runSql() {
                var _this = this;
                _this.mysqlPool.getConnection(function(err,connection){
                    if(err){
                        console.log(err);
                        return;
                    }
                    var sql = "show databases";
                    connection.query(sql, function(err,result){
                        connection.release();
                        if(err){
                            console.log(err);
                            return;
                        }
                        if(result.length > 0) {
                            _this.table_head = [];
                            let j = {};
                            j.type = 'selection';
                            j.width = 50;
                            j.align = 'center';
                            _this.table_head.push(j);
                            for (var i = 0; i < 1; i++) {
                                let keys = Object.keys(result[i]);
                                for (let key of keys) {
                                    let j = {};
                                    j.title = key;
                                    j.key = key;
                                    _this.table_head.push(j);
                                }
                            }
                            _this.table_data = [];
                            for (let obj of result) {
                                _this.table_data.push(obj);
                            }
                        }
                    })
                })

            }
        },
        created : function() {
            this.mysqlPool = getMysqlPool();
            console.log("this.mysqlPool---" + this.mysqlPool);


            this.runSql();
        }
    }
</script>

<style scoped>

</style>